//
//  HACMultiMLineNode.m
//  HStockCharts
//
//  Created by Hotacool on 2018/11/15.
//

#import "HACMultiMLineNode.h"

@implementation HACMultiMLineNode

- (instancetype)init {
    if (self = [super init]) {
        self.divideCount = 241;
    }
    return self;
}

- (void)setUp {
    [super setUp];
    self.yAxisCount = 6;
}

#pragma mark - provider protocol
- (NSArray *)lineDatasInRect:(CGRect)rect {
    NSMutableArray *drawingData = (NSMutableArray *)[super lineDatasInRect:rect];
    if (drawingData && drawingData.count > 0) {
        drawingData = [[NSMutableArray alloc] initWithArray:drawingData
                                                  copyItems:YES];
        for (HACLineComponents *lineItem in drawingData) {
            NSMutableArray *tmp = [NSMutableArray arrayWithArray:lineItem.pointArray];
            int m = (int)(lineItem.pointArray.count / self.divideCount);
            int a = (int)(lineItem.pointArray.count % self.divideCount);
            if (a == 0) {
                m -= 1;
            }
            if (m > 0) {
                for (int i = 1; i <= m; i++) {
                    NSInteger idx = i*self.divideCount + i - 1;
                    if (idx < lineItem.pointArray.count) {
                        CGPoint point = CGPointFromString(lineItem.pointArray[idx]);
                        [tmp insertObject:NSStringFromCGPoint(CGPointMake(point.x, kDrawingInvaildValue)) atIndex:idx];
                    }
                }
            }
            lineItem.pointArray = tmp;
        }
    }
    return drawingData;
}
@end
